import Vue from 'vue'
import VueRouter from 'vue-router'
import Index from '../views/Index.vue'

Vue.use(VueRouter)
import vueRsource from 'vue-resource'

Vue.use(vueRsource);
import store from '@/store/index.js'

const RestaurantDetail = (resolve) => {
  import('../views/restaurant-detail/restaurant-detail.vue').then((module) => {
    resolve(module)
  })
}
const Goods = (resolve) => {
  import('../views/restaurant-detail/goods/goods.vue').then((module) => {
    resolve(module)
  })
}
const Ratings = (resolve) => {
  import('../views/restaurant-detail/ratings/ratings.vue').then((module) => {
    resolve(module)
  })
}
const Seller = (resolve) => {
  import('../views/restaurant-detail/seller/seller.vue').then((module) => {
    resolve(module)
  })
}

const routes = [{
        path: '/',//路径
        component: Index,
        children: [{
            path: '',
            redirect: '/home'
          },
          {
            path: '/home',
            name: 'Home',
            component: () => import("../views/index/index.vue")
          },
          {
            path: '/shipu',
            name: 'shipu',
            component: () => import("../views/shipu.vue")
          },
          {
            path: '/gouwuche',
            name: 'gouwuche',
            component: () => import("../views/order/index.vue")
          },
          {
            path: '/me',
            name: 'Me',
            component: () => import("../views/Me.vue")
          },  
          // 商家模块
          {
            path: '/restaurant',
            redirect: '/restaurant/goods',
            component: RestaurantDetail,
            children: [
              {
                path: 'goods',
                component: Goods
              },
              {
                path: 'ratings',
                component: Ratings
              },
              {
                path: 'seller',
                component: Seller
              }
            ]
          },
        ]
      },
      {
        path: '/login',
        name: 'Login',
        component: () => import('../views/Login.vue')
      },
      {
        path:'/address',
        name:'Address',
        component:()=>import('../views/Address.vue')
      },
      {
        path:'/addAddress',
        name:'AddAddress',
        component:()=>import('../views/AddAddress.vue')
      },
      {
        path:'/addressSelect',
        name:'AddressSelect',
        component:()=>import('../views/AddressSelect.vue')
      },
      {
        path: '/book',
        name: 'Book',
        component: () => import('../views/Book.vue')
      },
      {
        path:'/edit',
        name:'Edit',
        component:()=>import('../views/Edit.vue')
      },
      {
        path:'/clausepolicy',
        name:'ClausePolicy',
        component:()=>import('../views/ClausePolicy.vue')
      },
      {
        path:'/customerService',
        name:'CustomerService',
        component:()=>import('../views/CustomerService.vue')
      }
    ]
    
 
const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes,
})


router.beforeEach((to, from, next) => {
  if (to.name === 'Login'  || store.getters.userInfo != null) {
    next()
  } else {
    next({
      name: 'Login'
    })
  }
})

      export default router